#ifndef D821249B_420A_4F3C_B251_88505CF25DD8
#define D821249B_420A_4F3C_B251_88505CF25DD8

#include <pthread.h>
#include <iostream>
#include <ctime>
#include <unistd.h>
#include <vector>
#include <queue>

typedef void (*callback)(void*);

static int num = 1;

class thread{
private:
	static void* routine(void* args)
	{
		thread* t = static_cast<thread*>(args);
		t->Entery();
		return nullptr;
	}

public:
	thread(callback cb): cb_(cb),threadname_(""),isrunning(false),start_time_stamp_(0)
	{}
	void run(void* args = nullptr)
	{
		threadname_ = "thread-" + std::to_string(num++);
		isrunning = true;
		start_time_stamp_ = time(nullptr);
		args_ = args;
		pthread_create(&tid,nullptr,routine,this);
	}
	void Join()
	{
		pthread_join(tid,nullptr);
		isrunning = false;
	}
	bool Isrunning()
	{
		return isrunning;
	}
	uint64_t Starttimestamp()
	{
		return start_time_stamp_;
	}
	std::string name() const
	{
		return threadname_;
	}
	void Entery()
	{
		cb_(args_);
	}
	pthread_t thread_self() const
	{
		return tid;
	}
private:
	pthread_t tid;
	std::string threadname_;
	callback cb_;
	bool isrunning;
	uint64_t start_time_stamp_;
	void* args_;
};

#endif /* D821249B_420A_4F3C_B251_88505CF25DD8 */
